<!doctype html>
<html>
 <head>
  <meta charset="UTF-8"></meta>
  <title>绑定邮箱</title>
  <link rel="stylesheet" href="/static/layui/css/layui.css"></link>
  <script type="text/javascript" src="/static/fsLayui/plugins/jquery/jquery.min.js"></script>
 </head>
<body style="height: 200px;">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
  <legend>第一次登录请输入用户名和邮箱</legend>
</fieldset>
	<form class="layui-form" action="/user/bindEmail" method="post" style="text-align: center;">
		<div class="layui-form-item" style="margin-bottom: 5px;">
			<label class="layui-form-label">用&nbsp;&nbsp;户&nbsp;&nbsp;名</label>
			<div class="layui-input-inline">
				<input type="text" name="userName" required=""
					lay-verify="userName" placeholder="请输入用户名（用于普通登录）" autocomplete="off"
					class="layui-input" style="width: 280px;" />
			</div>
		</div>

		<div class="layui-form-item" style="margin-bottom: 5px;">
			<label class="layui-form-label">邮&nbsp;&nbsp;箱</label>
			<div class="layui-input-inline">
				<input type="text" name="email" required=""
					   lay-verify="email" placeholder="请输入邮箱(用于找回密码)" autocomplete="off"
					   class="layui-input" style="width: 280px;" />
			</div>
		</div>

		 <div class="layui-form-item" style="text-align: center;margin-top: 15px;">
			<button class="layui-btn layui-btn-normal layui-btn-radius" lay-submit="" lay-filter="checkForm" style="width: 300px;">确认绑定</button>
		</div>
		<a style="color: red;">普通登录的初始密码是：123456 （尽快修改）</a><br/>
		<a style="color: red;">如果您已有账号请在登录后到用户中心进行绑定。</a> <a onclick="removeTempLogin()" style="color: #4F99CF;cursor:pointer;">去首页</a>
</form>
    <!-- layui.js -->
    <script src="/static/layui/layui.js"></script>
      <script src="/static/layui/layui.all.js"></script>
<script type="text/javascript">
		
		layui.form.verify({
		  //我们既支持上述函数式的方式，也支持下述数组的形式
		  //数组的两个值分别代表：[正则匹配、匹配不符时的提示文字]
            userName: [
                /^[\S]{5,15}$/
                ,'用户名必须5到15位，且不能出现空格'
            ]
		});
	
		layui.use('form', function() {
			var form = layui.form;
	
			//监听提交
			form.on('submit(checkForm)', function(data) {
				//layer.msg(JSON.stringify(data.field));
				 var url = '/user/bindEmail';
			        var data = $('form').serializeArray();
			        $.ajax({
			            type: "POST",
			            url: url,
			            data: data,
			            success: function (res) {
			                if(res.success){
			                	layer.msg('绑定成功！', {
			                		  icon: 1,
			                		  time: 1000 //2秒关闭（如果不配置，默认是3秒）
			                		}, function(){
			                		  //do something
					                	var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					            		parent.location.reload();
					            		parent.layer.close(index); //再执行关闭 
			                		});  
			                }
			                else{
			                	layer.msg(res.errorInfo);
			                }
			            },
			            error: function(data) {
			            	layer.msg("网络错误！");
			            }
			        });
				return false;
			});
		});

		function removeTempLogin() {
            top.location.href='/QQ/removeTempLogin';
        }
		
</script>
	
</body>
</html>